#include "PowerMaxBuff.h"
#include "StateBar.h"
#include "Power5Buff.h"


PowerMaxBuff::PowerMaxBuff(void)
{
	_weaponLvlBackup = 0;
}


PowerMaxBuff::~PowerMaxBuff(void)
{
}

void PowerMaxBuff::onStart(StateBar* stateBar)
{
	// Check if exist Power 5
	CCArray* listBuff = stateBar->getBuffs();
	CCObject* it;
	CCARRAY_FOREACH(listBuff, it)
	{
		Power5Buff* buff5 = dynamic_cast<Power5Buff*>(it);
		if (buff5)
		{
			stateBar->removeBuff(buff5);
		}
	}

	_weaponLvlBackup = getPlane()->getWeaponLevel();
	getPlane()->setWeaponLevel(getPlane()->getSupportedWeaponKeys()->count());
}

void PowerMaxBuff::onComplete()
{
	getPlane()->setWeaponLevel(_weaponLvlBackup);
}

bool PowerMaxBuff::init()
{
	if (!BaseBuff::init())
		return false;

	CCSprite* sprite = CCSprite::createWithSpriteFrameName("power_max_icon.png");
	sprite->setAnchorPoint(ccp(0.5f, 0.5f));
	sprite->setPosition(ccp(getBlackMask()->boundingBox().getMidX(), getBlackMask()->boundingBox().getMidY()));
	addChild(sprite, 0);

	getBlackMask()->setScaleY(1.0f);

	return true;
}
